import { defineStore } from "pinia";
import { ref } from "vue";

export const usePersistStore = defineStore(
  "persist",
  () => {
    //全部的RFid号
    const rfidAllList = ref([]);
    //可用的RFid号
    const rfidAvailableList = ref([]);
    //单料烟概览数据
    const overviewData = ref({
      year: "",
      location: null,
      categories: null,
      extra: null,
    });
    //单料年份条形统计图数据
    const barChartXData = ref([]);
    const barChartYData = ref([]);
    //单料烟地点分布地图数据
    const mapChartData = ref([]);
    // //员工
    // const employeeList = ref([]);
    // const empTotal = ref(0);

    //备料基本信息
    const extraList = ref([]);
    const extraTotal = ref(0);
    //单料烟基本信息
    const tobaccoList = ref([]);
    const tobTotal = ref(0);
    //缺料信息
    const shortList = ref([]);

    //叶组信息
    const groupTotal = ref(0);
    const groupList = ref([]);
    //用户相关
    const userInfo = ref({
      employeeId: "",
      id: "",
      //identity: "",
      job: "",
      name: "",
      password: "",
      //phoneNum: "",
      token: "",
    });
    return {
      //rfid号相关
      rfidAllList,
      rfidAvailableList,
      //数据展示相关
      overviewData,
      barChartXData,
      barChartYData,
      mapChartData,
      // //员工相关
      // employeeList,
      // empTotal,
      //单料烟相关
      tobaccoList,
      tobTotal,
      extraList,
      extraTotal,
      shortList,
      //叶组相关
      groupList,
      groupTotal,
      //用户相关
      userInfo,
    };
  },
  {
    persist: {
      //设置存储模式为 sessionStorage,
      //浏览器关闭以后自动清除缓存
      storage: sessionStorage,
      paths: [
        "rfidAllList",
        "rfidAvailableList",
        "overviewData",
        "barChartXData",
        "barChartYData",
        "mapChartData",
        // "employeeList",
        // "empTotal",
        "tobaccoList",
        "tobTotal",
        "extraList",
        "shortList",
        "extraTotal",
        "groupList",
        "groupTotal",
        "userInfo",
        "barChartXData",
        "barChartYData",
      ],
    },
  }
);
